<ul>
	<li><a href="/">Главная</a></li>
<?php
$query = "SELECT node.page_link_text, node.page_filesystem_name, (COUNT(parent.page_filesystem_name) - (sub_tree.depth + 1)) AS depth
		FROM kse_site_pages AS node,
			kse_site_pages AS parent,
			kse_site_pages AS sub_parent,
			(
				SELECT node.page_filesystem_name, (COUNT(parent.page_filesystem_name) - 1) AS depth
				FROM kse_site_pages AS node,
				kse_site_pages AS parent
				WHERE node.page_lft BETWEEN parent.page_lft AND parent.page_rgt
				AND node.page_filesystem_name = 'root'
				GROUP BY node.page_filesystem_name
				ORDER BY node.page_lft
			)AS sub_tree
		WHERE node.page_lft BETWEEN parent.page_lft AND parent.page_rgt
			AND node.page_lft BETWEEN sub_parent.page_lft AND sub_parent.page_rgt
			AND sub_parent.page_filesystem_name = sub_tree.page_filesystem_name
			AND node.page_slvl>=2
		GROUP BY node.page_filesystem_name
		HAVING depth = 1
		ORDER BY node.page_lft";
				
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
	echo "<li><a href=\"". $row["page_filesystem_name"] ."\">". $row["page_link_text"] ."</a></li>";	
}
?>
</ul>